import {
  FriendRequest,
  FriendRequestStatus,
  FriendRequestType,
} from "@/types/friend-request";

// 生成随机头像URL
const getRandomAvatar = () => {
  const avatarIds = [
    "1",
    "2",
    "3",
    "4",
    "5",
    "6",
    "7",
    "8",
    "9",
    "10",
    "11",
    "12",
    "13",
    "14",
    "15",
    "16",
    "17",
    "18",
    "19",
    "20",
  ];
  const randomId = avatarIds[Math.floor(Math.random() * avatarIds.length)];
  return `https://i.pravatar.cc/150?img=${randomId}`;
};

// 生成随机时间
const getRandomTime = () => {
  const now = new Date();
  const randomMinutes = Math.floor(Math.random() * 60 * 24 * 7); // 随机一周内的时间
  const time = new Date(now.getTime() - randomMinutes * 60000);

  return time.toLocaleString("zh-CN", {
    month: "numeric",
    day: "numeric",
    hour: "2-digit",
    minute: "2-digit",
  });
};

// 生成随机验证消息
const getRandomMessage = () => {
  const messages = [
    "你好，我是你的同学",
    "我们在会议上见过，加个好友吧",
    "我是小红介绍的朋友",
    "我在朋友圈看到你发的内容很有趣",
    "我们是一个群里的",
    "我是新来的同事",
    "听说你也喜欢摄影，交个朋友吧",
    "你好，我是张三的表弟",
    "我们上周在聚会上见过",
    "我是李四推荐来的",
  ];
  return messages[Math.floor(Math.random() * messages.length)];
};

// 生成随机状态
const getRandomStatus = () => {
  const statuses = [
    FriendRequestStatus.PENDING,
    FriendRequestStatus.ACCEPTED,
    FriendRequestStatus.REJECTED,
    FriendRequestStatus.PENDING, // 增加PENDING的权重
    FriendRequestStatus.PENDING,
  ];
  return statuses[Math.floor(Math.random() * statuses.length)];
};

// 生成随机昵称
const getRandomNickname = () => {
  const firstNames = [
    "张",
    "王",
    "李",
    "赵",
    "刘",
    "陈",
    "杨",
    "黄",
    "周",
    "吴",
  ];
  const lastNames = [
    "小",
    "大",
    "明",
    "华",
    "强",
    "伟",
    "芳",
    "娜",
    "军",
    "英",
  ];
  const nicknames = [
    "快乐的",
    "忧伤的",
    "聪明的",
    "可爱的",
    "帅气的",
    "温柔的",
    "活泼的",
    "沉默的",
    "热情的",
    "冷静的",
  ];

  const randomType = Math.floor(Math.random() * 3);

  if (randomType === 0) {
    return `${firstNames[Math.floor(Math.random() * firstNames.length)]}${
      lastNames[Math.floor(Math.random() * lastNames.length)]
    }`;
  } else if (randomType === 1) {
    return `${nicknames[Math.floor(Math.random() * nicknames.length)]}${
      firstNames[Math.floor(Math.random() * firstNames.length)]
    }${lastNames[Math.floor(Math.random() * lastNames.length)]}`;
  } else {
    return `${firstNames[Math.floor(Math.random() * firstNames.length)]}${
      lastNames[Math.floor(Math.random() * lastNames.length)]
    }${Math.floor(Math.random() * 1000)}`;
  }
};

// 生成模拟的好友申请数据
export const generateMockFriendRequests = (
  count: number = 10
): FriendRequest[] => {
  const requests: FriendRequest[] = [];

  for (let i = 0; i < count; i++) {
    requests.push({
      id: `request-${i + 1}`,
      fromId: `user-${i + 100}`,
      toId: "current-user",
      nickname: getRandomNickname(),
      avatar: getRandomAvatar(),
      message: getRandomMessage(),
      status: getRandomStatus(),
      type: FriendRequestType.APPLY,
      createTime: getRandomTime(),
    });
  }

  return requests;
};

// 导出模拟数据
export const mockFriendRequests = generateMockFriendRequests(15);
